# Contributor: Mark Riedesel <mark@klowner.com>
# Maintainer: Mark Riedesel <mark@klowner.com>
pkgname=openimageio
pkgver=2.1.18.1
pkgrel=0
pkgdesc="Image I/O library supporting a multitude of image formats"
options="!check" # 100 out of 120 tests fail
url="https://sites.google.com/site/openimageio/"
arch="all !mips !mips64 !s390x"
# s390x, mips, mips64 has missing dependency ptex-dev
license="BSD-3-Clause"
# NOTE: OpenColorIO and OpenImageIO are cross dependent. If an ABI incompatible
# update is done in one, the other also needs to be rebuilt.
makedepends="cmake boost-dev tiff-dev openexr-dev bzip2-dev freetype-dev hdf5-dev
	opencolorio-dev libtbb-dev libtbb ffmpeg-dev giflib-dev libheif-dev
	libraw-dev openjpeg-dev ptex-dev ptex mesa-dev libwebp-dev
	qt5-qtbase-dev fmt-dev python3-dev py3-pybind11-dev"
subpackages="py3-$pkgname:_python $pkgname-dev $pkgname-doc $pkgname-tools"
source="$pkgname-$pkgver.tar.gz::https://github.com/OpenImageIO/oiio/archive/Release-$pkgver.tar.gz
	0001-fix-sign-compare-error.patch"
builddir="$srcdir/oiio-Release-$pkgver"

build() {
	local _py_version=$(python3 --version | cut -c 8-10)
	local _iv="ON"

	case "$CARCH" in aarch64 | armv7 | armhf)
		_iv="OFF";;
	esac

	cmake -B build \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_SKIP_RPATH=ON \
		-DPYTHON_VERSION=$_py_version \
		-DOIIO_BUILD_TESTS=OFF \
		-DSTOP_ON_WARNING=OFF \
		-DENABLE_iv=$_iv \
		-DINSTALL_FONTS=OFF
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --build build --target install
}

tools() {
	pkgdesc="Tools for manipulating a multitude of image formats"

	mkdir -p "$subpkgdir"/usr
	mv "$pkgdir"/usr/bin "$subpkgdir"/usr/
}

_python() {
	local pyver="${subpkgname:2:1}"
	pkgdesc="Python $pyver bindings for OpenImageIO image I/O library"
	depends="python$pyver"

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/python$pyver* "$subpkgdir"/usr/lib/
}

sha512sums="4ce0f7f104e391bc20f1491dd5519aecb8044efcd0cacd1c4e941ec1e383276024b4e85c5db8c88d234568a65525beb50bf1fa81feed0dd401cb602eee5c782a  openimageio-2.1.18.1.tar.gz
25788863c278ac68356b2eb6b1f2b31e1867366f4c1aa6654cfcf8c708de084f69695093de6c2038137742a67908a21f1c3ecc7c679919eaccac6d5b310da087  0001-fix-sign-compare-error.patch"
